﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using jmvc.Models.Contacts;

namespace jmvc.Controllers
{
	public class ContactsController : Controller
	{
		private static List<Contact> Contacts = new List<Contact>();

		static ContactsController()
		{
			Contacts.Add(new Contact()
			{
				Id = 1000,
				Name = "John Doe"
			});
			Contacts.Add(new Contact()
			{
				Id = 1001,
				Name = "Mary Jones"
			});
			Contacts.Add(new Contact()
			{
				Id = 1002,
				Name = "Peter Johnson"
			});
		}

		[HttpGet]
		public JsonResult Index(int? id)
		{
			if (id.HasValue)
				return Json(Contacts.FirstOrDefault(c => c.Id == id.Value), JsonRequestBehavior.AllowGet);
			return Json(Contacts, JsonRequestBehavior.AllowGet);
		}
	}
}